package org.com.blbl.Client;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class ClientMapper extends Mapper<Object, Text, Text, IntWritable> {
    private final static IntWritable one = new IntWritable(1);
    private Text deviceType = new Text();

    @Override
    protected void map(Object key, Text value, Context context) throws IOException, InterruptedException {
        String[] fields = value.toString().split(",");
        String type = fields[3].trim();
        if (type.equals("pc") || type.equals("android") || type.equals("ios")) {
            deviceType.set(type);
            context.write(deviceType, one); // 输出设备类型和数量1
        }
    }
}
